#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QProgressDialog>
#include <QThread>
#include <QMessageBox>


#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}




void MainWindow::on_pushButton_selectDbc_clicked()
{
    ui->lineEdit_dbc->setText(QFileDialog::getOpenFileName(this));
  //  dbcLoader.load(dbcPath, dbc);
}

void MainWindow::on_pushButton_selectCodePath_clicked()
{
    ui->lineEdit_codePath->setText(QFileDialog::getExistingDirectory());
}

void MainWindow::on_pushButton_genCode_clicked()
{
    dbcClass dbc;
    QString dbcPath = ui->lineEdit_dbc->text();
    if(dbcPath.isEmpty())
    {
        QMessageBox::information(nullptr, "", "dbc路径不太对");
        return;
    }
    QString codePath = ui->lineEdit_codePath->text();
    if(codePath.isEmpty())
    {
        QMessageBox::information(nullptr, "", "代码保存路径不太对");
        return;
    }
    dbcLoader.load(dbcPath,dbc);
    coder.pushCode(dbc,codePath);

//    QProgressDialog progress("代码生成中", "中止", 0, 100, nullptr);
//    progress.setWindowModality(Qt::WindowModal);
//    int i;
//    for(i=0; i<100; i++)
//    {
//        progress.setValue(i);
//        QThread::msleep(100);
//    }
}
